const { query } = require('./config/database')

async function checkUserRole () {
  try {
    console.log('🔍 检查管理员账号角色信息...')

    const result = await query(
      'SELECT id, username, email, role, is_vip, coins FROM users WHERE email = ?',
      ['1477042095@qq.com']
    )

    if (result.length > 0) {
      console.log('✅ 管理员账号信息:')
      console.table(result)

      const user = result[0]
      console.log('\n📋 详细信息:')
      console.log(`- ID: ${user.id}`)
      console.log(`- 用户名: ${user.username}`)
      console.log(`- 邮箱: ${user.email}`)
      console.log(`- 角色: ${user.role}`)
      console.log(`- VIP状态: ${user.is_vip ? '是' : '否'}`)
      console.log(`- 金币余额: ${user.coins}`)

      if (user.role !== 'admin') {
        console.log('\n⚠️  警告：用户角色不是admin，正在更新...')
        await query('UPDATE users SET role = ? WHERE email = ?', [
          'admin',
          '1477042095@qq.com'
        ])
        console.log('✅ 角色已更新为admin')

        // 再次查询验证
        const updatedResult = await query(
          'SELECT id, username, email, role, is_vip FROM users WHERE email = ?',
          ['1477042095@qq.com']
        )
        console.log('✅ 更新后的信息:')
        console.table(updatedResult)
      }
    } else {
      console.log('❌ 未找到管理员账号')
    }
  } catch (error) {
    console.error('❌ 错误:', error.message)
  }

  process.exit(0)
}

checkUserRole()
